﻿// /////////////////////////////////////////////////////////////////////
// 
//  Codeplex JSAnalyse
//  Copyright (c) 2011
//  JSAnalyse.Validator   AllowedDependenciesLayerDiagram.cs
// 
// /////////////////////////////////////////////////////////////////////
using System.Collections.Generic;
using System.Linq;
using JSAnalyse.Core.Interfaces;

namespace JSAnalyse.Validator
{
    /// <summary>
    /// Visual Studio layer diagram dependency checker
    /// </summary>
    public class AllowedDependenciesLayerDiagram: IAllowedDependencies
    {
        private List<AllowedDependency> _allowedDependencyList;

        /// <summary>
        /// Initializes a new instance of the <see cref="AllowedDependenciesLayerDiagram"/> class.
        /// </summary>
        /// <param name="allowedDependencyList">The allowed dependency list.</param>
        public AllowedDependenciesLayerDiagram(List<AllowedDependency> allowedDependencyList)
        {
            _allowedDependencyList = allowedDependencyList;
        }

        /// <summary>
        /// Determines whether the dependency is allowed between the file and dependent File
        /// </summary>
        /// <param name="file">The base file</param>
        /// <param name="dependentFile">The dependent file</param>
        /// <returns>
        ///   <c>true</c> if the specified file is allowed; otherwise, <c>false</c>.
        /// </returns>
        public bool IsAllowed(string file, string dependentFile)
        {
            return _allowedDependencyList.FirstOrDefault(item => item.SourceFile == file && item.TargetFile == dependentFile) != null;
        }
    }
}
